/**
 * 标识控制器
 * @constructor
 */

var Identities = require('../models/Identities');
var co = require('co');
var Utils = require('../utils/Utils');
var response = require('../net/HttpResponse');

var IdentityController = function () {
};

IdentityController.prototype.addIdentity = function (req, res) {
  var body = req.body;
  co(function * () {
    var result = yield Identities.$manager.insert({
      code: body.code,
      name: body.name,
      category: req.params.category,
      appToken: body.apptoken,
      biz: body.biz
    });
    response(res)
      .ok()
      .send(result);
  }).catch(function (err) {
    response(res)
      .error(err.toString())
      .send();
  });
};

IdentityController.prototype.onRouting = function (router) {
  router.post('/add/:category', this.addIdentity);
};

module.exports = IdentityController;